package com.chinasi.web.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.caland.framework.core.page.Pager;
import com.chinasi.common.EntityType;
import com.chinasi.model.ConsultBasic;
import com.chinasi.model.ConsultBasic;
import com.chinasi.model.OrgQa;
import com.chinasi.service.BidConsultService;
import com.chinasi.service.ConsultBasicService;
import com.chinasi.service.OrgHonorService;
import com.chinasi.service.OrgQaService;
import com.chinasi.web.action.common.URLConstants;

/**
 * 产业实体：咨询机构
 * @author xzl
 *
 */
@Controller
@RequestMapping(value = URLConstants.CONSULT)
public class ConsultBasicAction {

	/**
	 * ConsultBasicService
	 */
	@Autowired
	private ConsultBasicService consultBasicService;
	
	@Autowired
	private BidConsultService bidConsultService;
	
	@Autowired
	private OrgQaService orgQaService;
	
	@Autowired
	private OrgHonorService orgHonorService;
	
	@RequestMapping("list")
	public ModelAndView list(ConsultBasic searchBean, HttpServletRequest request){
		Pager pager = consultBasicService.findPageCondition(searchBean,1);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		model.put("params", searchBean);
		model.put("entityType", EntityType.CONSULT.toString());
		model.put("menu", "CYDA");
		return new ModelAndView("cyst/consult_list",model);
	}
	
	/** 异步加载分页数据 */
	@RequestMapping("loadajax")
	public ModelAndView loadajax(HttpServletRequest request, HttpServletResponse response,ConsultBasic searchBean, int curpage){
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", consultBasicService.findPageCondition(searchBean,curpage));
		return new ModelAndView("fragment/fragment_consult_more", model);
	}
	
	/** 基本信息 */
	@RequestMapping("baseInfo")
	public ModelAndView baseInfo(String id){
		ConsultBasic consult = consultBasicService.findById(id);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/baseinfo", model);
	}
	
	/** 企业资质 */
	@RequestMapping("orgqa")
	public ModelAndView orgqa(String id, @RequestParam(defaultValue="1") int currentPage){
		ConsultBasic consult = consultBasicService.findById(id);
		Pager pager = orgQaService.findPageByOrgId(id,currentPage);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/orgqa", model);
	}
	
	/** 企业荣誉 */
	@RequestMapping("orghonor")
	public ModelAndView orghonor(String id, @RequestParam(defaultValue="1") int currentPage){
		ConsultBasic consult = consultBasicService.findById(id);
		Pager pager = orgHonorService.findPageByOrgId(id,currentPage);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/orghonor", model);
	}
	
	/** 项目案例 */
	@RequestMapping("implement_project")
	public ModelAndView implementProject(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsultBasic consult = consultBasicService.findById(id);
		
		Pager pager = bidConsultService.findRelationBid(consult.getConsultCode(), currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/implement_project", model);
	}
	
	/** 相关项目甲方 */
	@RequestMapping("rel_consumer")
	public ModelAndView relConsult(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsultBasic consult = consultBasicService.findById(id);

		Pager pager = bidConsultService.findRelationConsumer(consult, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/rel_consumer", model);
	}
	
	/** 相关集成商*/
	@RequestMapping("rel_integration")
	public ModelAndView relIntegration(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsultBasic consult = consultBasicService.findById(id);
		
		Pager pager = bidConsultService.findRelationIntegrator(consult, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/rel_integration", model);
	}
	
	/** 相关招标代理*/
	@RequestMapping("rel_agency")
	public ModelAndView relAgency(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsultBasic consult = consultBasicService.findById(id);
		
		Pager pager = bidConsultService.findRelationAgency(consult, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/rel_agency", model);
	}
	
	/** 相关招标代理*/
	@RequestMapping("rel_supervision")
	public ModelAndView relSupervision(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsultBasic consult = consultBasicService.findById(id);
		
		Pager pager = bidConsultService.findRelationSupervision(consult, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/rel_supervision", model);
	}
	
	/** 合作专家*/
	@RequestMapping("rel_expert")
	public ModelAndView relExpert(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsultBasic consult = consultBasicService.findById(id);
		
		Pager pager = bidConsultService.findRelationExpert(consult, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consult", consult);
		return new ModelAndView("cyst/consult/rel_expert", model);
	}
}
